package org.nvframe;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.nvframe.event.EventService;
import org.nvframe.event.eventtype.UpdateEvent;
import org.nvframe.manager.RenderManager;

public abstract class NVFrameGame extends BasicGame {
	
	protected boolean pauze;
	protected int pauzeKey = 0;
	
	public NVFrameGame(String title) {
		super(title);
	}

	@Override
	public void update(GameContainer gc, int delta) throws SlickException {
		if(pauzeKey != 0 && gc.getInput().isKeyPressed(pauzeKey))
			togglePauze();
		
		if(!pauze)
			EventService.getInstance().fireEvent(new UpdateEvent(gc, delta));
	}
	
	@Override
	public void render(GameContainer gc, Graphics gr) throws SlickException {
		RenderManager.getInstance().render(gc, null, gr);
	}
	
	public void setPauze(boolean pauze) {
		this.pauze = pauze;
	}
	
	public void togglePauze() {
		pauze = !pauze;
		System.out.println("pauze: " + pauze);
	}
	
	public void setPauzeKey(int key) {
		pauzeKey = key;
	}

}
